﻿
@{
    ViewBag.Title = "回单描述";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
<link rel="stylesheet" href="~/Content/css/easyui.css" />
<link rel="stylesheet" href="~/Content/css/weui.min.css">
<link rel="stylesheet" href="~/Content/css/jquery-weui.min.css">
<script src="~/Content/script/jquery-1.11.0.min.js"></script>
<script src="~/Content/script/jquery-weui-1.2.1.min.js"></script>
<script src="~/Content/script/jquery.easyui.min.js"></script>
<script src="~/Content/script/jquery.easyui-1.4.3.min.js"></script>

<div class="weui-cells weui-cells_form" style="bottom: 20px;">
    <div class="weui-cells__title" style="height:1.2rem">回单描述</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <textarea class="weui-textarea" id="FinishRemak" style="height:6.25rem" placeholder="请输入文本" rows="3"></textarea>
            </div>
        </div>
    </div>


</div>
<div class="weui-cells__tips">*信息可选填</div>

@*<div class="ui-btn-wrap" id="footer">
        <button class="ui-btn-primary">
            保存
        </button>
    </div>*@

<div class="weui-btn-area">
    <div id="replyGenset" class="weui-btn weui-btn_primary">回单</div>
</div>



@*<script src="~/Content/script/jweixin-1.4.0.js"></script>*@
<script>

    //获取Detail传过来的参数
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }


    var annouceCode = GetRequest()['annouceCode'];//拿到参数annouceCode
    var AnnounceStatus = GetRequest()['AnnounceStatus'];//拿到参数AnnounceStatus    判断是否直接回单
    var userCode=GetRequest()['userCode'];//拿到参数AnnounceStatus

    $("#replyGenset").click(function () {
        @*var AnnounceStatus=@Model.AnnounceList.AnnounceStatus;//判断是否直接回单
        var annouceCode = $("#annouceCode").html();
        var userCode = "@Model.AnnounceList.AcceptPersonCode";*@
        var FinishRemak = $("#FinishRemak").val().trim();
        $(".ui-actionsheet").removeClass("show");
        if (AnnounceStatus==20) {//直接回单，无需发电
            $.confirm("站址是否无需发电，直接回单？","提示",function () {
                $.ajax({
                    url: '/api/Annouce/UserDirectReceipt?annouceCode=' + annouceCode + '&userCode=' + userCode + '&FinishRemak=' + FinishRemak + '',
                    type: 'get',
                    beforeSend: function () {
                        $.showLoading("提交中...");
                    }, success: function (res) {
                        $.hideLoading();
                        console.log(res)
                        //var resd = JSON.parse(res);
                        res = res.Data
                        if (res.Code === 1) {
                            $.toast("操作成功");
                            setTimeout(function () {
                                location.href = "/AnnouceList/Detail?annouceCode=" + annouceCode + "";
                            }, 1 * 1000);
                        } else {
                            $.alert(res.Result);
                            return;
                        }
                    }
                })
            })
        }else {
            $.ajax({
                url:'/api/Annouce/IsBindGenRecord?annouceCode='+annouceCode+'',
                type:'get',
                success:function (data) {
                    //var res = JSON.parse(data)
                    var res = data;
                    if(res.Code==1)
                    {
                        $.confirm("是否执行此操作？", "提示", function () {
                            $.ajax({
                                url: '/api/Annouce/replyGensetMethod?annouceCode=' + annouceCode + '&userCode=' + userCode + '&FinishRemak=' + FinishRemak + '',
                                type: 'get',
                                beforeSend: function () {
                                    $.showLoading("提交中...");
                                }, success: function (res) {
                                    console.log(res)
                                    $.hideLoading();
                                    res = res.Data;

                                    //var resd = JSON.parse(res);
                                    if (res.Code === 1) {
                                        $.toast("操作成功");
                                        setTimeout(function () {
                                            location.href = "/AnnouceList/Detail?annouceCode=" + annouceCode + "";
                                        }, 1 * 1000);
                                    } else {
                                        $.alert(res.Result);
                                        return;
                                    }
                                }
                            })
                        }, function () {

                        })
                    }else {
                        $.confirm("此工单尚未存在发电记录，是否继续回单？", "提示", function () {
                            $.ajax({
                                url: '/api/Annouce/replyGensetMethod?annouceCode=' + annouceCode + '&userCode=' + userCode + '&FinishRemak=' + FinishRemak + '',
                                type: 'get',
                                beforeSend: function () {
                                    $.showLoading("提交中...");
                                }, success: function (res) {
                                    $.hideLoading();
                                    //var resd = JSON.parse(res);
                                    console.log(res)
                                    res = res.Data;
                                    if (res.Code === 1) {
                                        $.toast("操作成功");
                                        setTimeout(function () {
                                            location.href = "/AnnouceList/Detail?annouceCode=" + annouceCode + "";
                                        }, 1 * 1000);
                                    } else {
                                        $.alert(res.Result);
                                        return;
                                    }
                                }
                            })
                        }, function () {
                        })
                    }
                }
            })
        }
    })

</script>